/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bytedance.scenedemo.animatiom.sipnner;

import com.bytedance.scene.dialog.bottomsheet.LogUtil;
import ohos.aafwk.ability.Ability;
import ohos.agp.components.ComponentContainer;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.service.WindowManager;
import ohos.app.Context;
import ohos.multimodalinput.event.TouchEvent;

/**
 * FullScreenDialog.
 *
 * @since 2021-06-17
 */
public class FullScreenDialog extends CommonDialog {
    private BasePopupView contentView;
    private Context context;

    /**
     * FullScreenDialog
     *
     * @param context Context
     */
    public FullScreenDialog(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        if (getWindow() == null || contentView == null || contentView.getPopupInfo() == null) {
            return;
        }
        if (contentView.getPopupInfo().isEnableShowWhenAppBackground()) {
            // 支持悬浮窗（即应用后台弹出Xpopup）
            WindowManager.LayoutConfig layoutConfig = getWindow().getLayoutConfig().get();
            layoutConfig.type = WindowManager.LayoutConfig.MOD_APPLICATION_OVERLAY;
            getWindow().setLayoutConfig(layoutConfig);
        }
        setTransparent(true);
        setSize(PopupUtils.getWindowWdith(context), PopupUtils.getWindowHeight(context));
        if (!contentView.getPopupInfo().isRequestFocus()) {
            // 不获取焦点
            LogUtil.info("XPopup", "waiting for improvement");
        }
        autoSetStatusBarMode(); // 自动设置状态色调，亮色还是暗色
        contentView.setLayoutConfig(new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,
                ComponentContainer.LayoutConfig.MATCH_PARENT));
        setContentCustomComponent(contentView);
    }

    /**
     * 是否是亮色调状态栏
     */
    public void autoSetStatusBarMode() {
        // 隐藏状态栏
        if (!contentView.getPopupInfo().getHasStatusBar()) {
            return;
        }
    }

    /**
     * setContent
     *
     * @param view BasePopupView
     * @return FullScreenDialog
     */
    public FullScreenDialog setContent(BasePopupView view) {
        this.contentView = view;
        return this;
    }

    /**
     * 把事件传递给Ability，暂无实现
     *
     * @param event 触摸事件
     */
    public void passClick(TouchEvent event) {
        if (contentView != null && contentView.getContext() instanceof Ability) {
            // 把事件传递给Ability，暂无实现
            LogUtil.info("XPopup", "waiting for improvement");
        }
    }
}
